package com.msmall.community.bbs.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.base.cache.CacheFactory;
import com.msmall.base.pager.PaginationSupport;
import com.msmall.base.util.Constants;
import com.msmall.base.util.Util;
import com.msmall.community.bbs.model.Topic;
import com.msmall.community.bbs.service.SearchManager;
import com.msmall.community.bbs.service.TopicManager;


public class SearchManagerImpl implements SearchManager{

	protected final Log log = LogFactory.getLog(getClass());
	
	private TopicManager topicManager;
	
	public void setTopicManager(TopicManager topicManager) {
		this.topicManager = topicManager;
	}

	public void search(PaginationSupport page, String searchContent, String searchType) {
		if("1".equals(searchType))
			searchByTitle(page, searchContent);
		if("2".equals(searchType))
			searchByAuthor(page, searchContent);
	}
	
	public void searchByAuthor(PaginationSupport page, String author){
		author = author.trim();
		page.setClazz(Topic.class);
		page.setPageSize(10);
		String queryString = " from Topic t,UserInfo u where u.username='" + author +"' and t.userid=u.userId and t.enabled=1 order by t.createTime desc";
		page.setQueryString(queryString);
		topicManager.getPagination(page);
	}

	public void searchByTitle(PaginationSupport page, String title){
		title = title.trim();
		page.setClazz(Topic.class);
		page.setPageSize(10);
		String queryString = " from Topic t where t.title like '%" + title +"%' and t.enabled=1 order by t.createTime desc";
		page.setQueryString(queryString);
		topicManager.getPagination(page);
	}
}